package service;

import dao.ImplementUser;
import pojo.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/updateUserServlet")
public class UpdateUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String id=req.getParameter("id");
        String usename=req.getParameter("usename");
        String password=req.getParameter("password");
        String telephone=req.getParameter("telephone");
        String gender=req.getParameter("gender");
        String age=req.getParameter("age");
        ImplementUser implementUser=new ImplementUser();
                implementUser.update(usename,password,gender,telephone,age);
                User newuser=new User();
        try {
            newuser= implementUser.finduser(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    resp.sendRedirect(req.getContextPath()+"/userInformation.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
